'''
Created on Feb 25, 2019

@author: oelfarou
'''
class PID(object):
    
    
    def __init__(self,p,i,d,delta_t):
        self.p = p
        self.i = i
        self.d = d
        self.delta_t = delta_t
        
        self.p_error = 0.0
        self.i_error = 0.0
        self.d_error = 0.0
        
        self.prev_error = 0.0
        self.total_error = 0.0
        
        
    def update(self,feedback):
        
        self.total_error = self.total_error + feedback
        self.p_error = self.p *feedback
        self.i_error = self.i *self.total_error
        self.d_error = (self.d * feedback) - self.prev_error
        self.prev_error = feedback
        
        return self.p_error + self.i_error + self.d_error
        